const canvas = document.getElementById('canvas')
const context = canvas.getContext("2d")
const btn = document.querySelector('.begin-text')
const startjframe = document.querySelector('.startJframe')
const gamejframe = document.querySelector('.game-jframe')
const menu = document.querySelector('.menu')
const menu_btn = document.querySelector('.menu .menu_btn')
const audio1 = document.querySelector('.backgroundMusic1')
const audio2 = document.querySelector('.backgroundMusic2')
const point = document.querySelector('.point')

canvas.width = 1120 * devicePixelRatio;
canvas.height = 620 * devicePixelRatio;
context.scale(devicePixelRatio, devicePixelRatio);

//创建生成图片的方法
function getImageBySrc(src) {
  let img = new Image()
  img.src = './images/' + src
  return img;
}


//储存图片对象
const allImgSrcObj = {
  stepNull: 'interface/stepnulll.png',
  stepFull: 'interface/stepfulll.png',
  sunbg: '卡槽/ChooserBackground.png',
  bullet: 'interface/PeaBullet.png',
  bulletHit: 'interface/PeaBulletHit.png',
  shovel: 'interface/Shovel.png',
  shovelbg: 'interface/ShovelBack.png',
  car: 'interface/LawnCleaner.png',
  win: 'interface/trophy.png',
  prepare: 'interface/PrepareGrowPlants.gif',
  zombieswin: 'interface/ZombiesWon.png',
  exit1: 'interface/exit1.png',

  //储存植物卡槽图片对象
  plantCard: {
    //豌豆射手
    peashooter: {
      src: '卡槽/card_1.png'
    },
    //向日葵
    sunflower: {
      src: '卡槽/card_2.png'
    },
    //食人花
    chomper: {
      src: '卡槽/card_3.png'
    },
    //樱桃炸弹
    cherrybomb: {
      src: '卡槽/card_4.png'
    },
    //寒冰射手
    snowpea: {
      src: '卡槽/card_snowpea.png'
    },
    wallnut: {
      src: '卡槽/card_wallnut.png'
    }
  },
  plants: {
    sunflower: {  // 向日葵
      pic: 'Plants/sunflower/idle/idle_00.png',
      idle: {
        src: 'Plants/sunflower/idle/idle_*.png',
        len: 18,
      },
    },
    peashooter: { // 豌豆射手
      pic: 'Plants/peashooter/idle/idle_00.png',
      idle: {
        src: 'Plants/peashooter/idle/idle_*.png',
        len: 8,
      },
      attack: {
        src: 'Plants/peashooter/attack/attack_*.png',
        len: 8,
      },
    },
    repeater: { // 双发射手
      pic: 'Plants/repeater/idle/idle_00.png',
      idle: {
        src: 'Plants/repeater/idle/idle_*.png',
        len: 15,
      },
      attack: {
        src: 'Plants/repeater/attack/attack_*.png',
        len: 15,
      },
    },
    cherrybomb: { // 樱桃炸弹
      pic: 'Plants/cherrybomb/idle/idle_00.png',
      idle: {
        src: 'Plants/cherrybomb/idle/idle_*.png',
        len: 7,
      },
      attack: {
        src: 'Plants/cherrybomb/attack/attack_*.png',
        len: 5,
      },
    },
    wallnut: { // 坚果墙
      pic: 'Plants/wallnut/idleH/idleH_00.png',
      idleH: { // 血量高时动画
        src: 'Plants/wallnut/idleH/idleH_*.png',
        len: 16,
      },
      idleM: { // 血量中等时动画
        src: 'Plants/wallnut/idleM/idleM_*.png',
        len: 11,
      },
      idleL: { // 血量低时动画
        src: 'Plants/wallnut/idleL/idleL_*.png',
        len: 15,
      },
    },
    chomper: { // 食人花
      pic: 'Plants/chomper/idle/idle_00.png',
      idle: { // 站立动画
        src: 'Plants/chomper/idle/idle_*.png',
        len: 13,
      },
      attack: { // 攻击动画
        src: 'Plants/chomper/attack/attack_*.png',
        len: 8,
      },
      digest: { // 消化阶段动画
        src: 'Plants/chomper/digest/digest_*.png',
        len: 6,
      }
    },
  },
  zombies: {// 僵尸
    idle: { // 站立动画
      src: 'Zombies/idle/idle_*.png',
      len: 31,
    },
    run: { // 移动动画
      src: 'Zombies/run/run_*.png',
      len: 31,
    },
    attack: { // 攻击动画
      src: 'Zombies/attack/attack_*.png',
      len: 21,
    },
    dieboom: { // 被炸死亡动画
      src: 'Zombies/dieboom/dieboom_*.png',
      len: 20,
    },
    die: {
      src: 'Zombies/die/body/body_*.png',
      len: 26,
    },


  }
}




